package webUtils.buzhidao;

import java.util.List;
import java.util.concurrent.Callable;

import org.apache.http.NameValuePair;
/**
* @author 作者 linweiqiang
* @version 创建时间：2017年9月29日 下午2:34:53
* 类说明
*/
public class HttpCallable implements Callable<String> {
private String url;
    
    private List<NameValuePair> jsonParams;
    
    public HttpCallable(String url, List<NameValuePair> jsonParams){
        this.url = url;
        this.jsonParams = jsonParams;
    }

    /**
     * 执行并返回结果
     */
    @Override
    public String call() throws Exception {
        return HttpTool.requestPost(url, jsonParams);
    }
    
    /**
     * 模拟并发测试
     * @throws Exception 
     * @throws UnsupportedEncodingException 
     */
    /*public static void main(String[] args) throws UnsupportedEncodingException, Exception {
        //模拟并发数
        int concurrencyNumber = 10;
        
        List<String>  resList = Lists.newArrayList();
        
        //执行线程池
        ExecutorService ex = Executors.newFixedThreadPool(100);
        
        String url = "http://127.0.0.1:8083/native/com.opentech.cloud.pay.api.trade/2.0.0";
        Map<String, String> mapPatam = new HashMap<>();
        mapPatam.put("name", "测试");
        
        
        for(int i =0 ; i< 2; i++){
        	List<NameValuePair> list = new ArrayList<NameValuePair>();
        	Map<String,String > params = new HashMap<String, String>();
			params.put("customerNo", "88888888");
			params.put("customerCerNo", "2017011822055618000");
			params.put("cusTradeNo", String.valueOf(System.currentTimeMillis()));
			params.put("currency", "CNY");
			params.put("tradeAmt", "10");
			params.put("payMethod", "WECHAT_QRCODE_PAY");
			params.put("subject", "哈哈哈");
			params.put("notifyURL", "http://127.0.0.1:8055/merchant/callback4trade.do");
			params.put("returnURL", "http://127.0.0.1:8055/merchant/return4trade.do");
			params.put("returnType", "JSON");
			Map<String,String> get = GetSign.getSign(params);
			for (String  key : get.keySet()) {
				System.out.println(get.get(key));
				list.add(new BasicNameValuePair(key, get.get(key)));
			}
            Future<String> callRes = ex.submit(new HttpCallable(url,list));
            resList.add(i + ">>>" + callRes.get());
        }
        
        for(String s : resList){
            System.out.println("------>" + s);
        }
    }*/
}
